package com.maslyk.invitation.entitybean;

import java.math.BigDecimal;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.maslyk.invitation.audit.ObjectName;
import com.maslyk.invitation.audit.PropertyLabel;
import com.maslyk.invitation.entitybean.abstrct.GenericEntity;


@Entity
@Table(name = "feeinvitation")
@ObjectName(label="Opłata dla zaproszenia")
public class FeeInvitation extends GenericEntity
{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
	private Integer id;

	@Column(name = "multiply")
	@PropertyLabel(label="Ilość")
	private Integer multiply = 1; // domyslnie oplata wliczana jest jednorazowo

	// bi-directional many-to-one association to Invitation
	@ManyToOne(fetch = FetchType.LAZY, cascade=CascadeType.REFRESH)
	@JoinColumn(name = "invitationid")
	private Invitation invitation;

	// bi-directional many-to-one association to Priceparameter
	@ManyToOne(fetch = FetchType.LAZY, cascade=CascadeType.REFRESH)
	@JoinColumn(name = "definitionid")
	private PriceParameter priceparameter;

	public FeeInvitation()
	{
	}

	public Integer getId()
	{
		return this.id;
	}

	public void setId(Integer id)
	{
		this.id = id;
	}

	public int getMultiply()
	{
		return this.multiply;
	}

	public void setMultiply(int multiply)
	{
		this.multiply = multiply;
	}

	public Invitation getInvitation()
	{
		return this.invitation;
	}

	public void setInvitation(Invitation invitation)
	{
		this.invitation = invitation;
	}

	public PriceParameter getPriceParameter()
	{
		return this.priceparameter;
	}

	public void setPriceParameter(PriceParameter priceparameter)
	{
		this.priceparameter = priceparameter;
	}

	public static String getBeanName()
	{
		return "feeInvitationBean";
	}
	
	public double getAmount()
	{
		double result = 0.00;
		
		result = priceparameter.getPrice().doubleValue() * (double)multiply;
		
        BigDecimal amount = new BigDecimal(result);
        amount.setScale(2,BigDecimal.ROUND_HALF_UP);
        return amount.doubleValue();
	}
	
	public String getKey() {
		return null;
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		
		FeeInvitation fee = (FeeInvitation) super.clone();
		fee.setId(null);
		fee.setInvitation(null);
		return fee;
	}
}